﻿/**
  *FileName:    fractal
  *Date:        23/4/10 周一 下午 1:16:45
  *Author:      Zhou Hang
  *Version:     1.0
  *Description: 分形
*/
#include <graphics.h>
#include <conio.h>
#include <math.h>
#define W 1200
#define H 1200
#define IMG_FILE "./mandelbrot.ppm"
using namespace std;

int x[W][H];

void Fractal() {
	//initgraph(W, H);
	//setbkcolor(WHITE);
	//cleardevice();

	for (int i = 0; i < W; i++)
		for (int j = 0; j < H; j++) {
			double a = 0, b = 0, c, d;
			while ((c = a * a) + (d = b * b) < 4 && x[i][j]++ < 880) {
				b = 2 * a * b + j * 1024.0 / H * 8e-9 - 0.645411;
				a = c - d + i * 1024.0 / W * 8e-9 + 0.356888;
			}
		}

	/*int step = 1;
	int w = W / step, h = H / step;
	for (int j = 0; j < H; j += step) {
		for (int i = 0; i < W; i += step) {
			int n = x[i][j];
			int r = 255 * pow((n - 80) / 800.0, 3);
			int g = 255 * pow((n - 80) / 800.0, 0.7);
			int b = 255 * pow((n - 80) / 800.0, 0.5);
			putpixel(i, j, RGB(r, g, b));
		}
	}*/

	//int key = _getch();
	//closegraph();
}
